//
//  WriteCommentViewController.m
//  Edumap
//
//  Created by 辰领科技 on 16/7/20.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "WriteCommentViewController.h"

@interface WriteCommentViewController ()
<UITextViewDelegate>

@property (strong, nonatomic) IBOutlet UIView *navView;
@property (strong, nonatomic) IBOutlet UIScrollView *scroview;
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@property (strong, nonatomic) IBOutlet UITextView *textView;
@property (strong, nonatomic) IBOutlet UILabel *label;
@property (strong, nonatomic) IBOutlet UIButton *submitButton;

@end

@implementation WriteCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initViewLayout];
}

- (void)initViewLayout {
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    [self adaptiveViewLayout:self.scroview];
    self.scroview.contentSize = flexibleSize(CGSizeMake(320, 504.5), YES);
    
    _submitButton.layer.cornerRadius = 5*VerticalRatio();
    
    self.textView.delegate = self;
    
    if (_image.length>0) {
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IP_Address_ImageDown_Fresh,_image]]];
    }
}

- (IBAction)back:(id)sender {
    [self backBtn];
}

#pragma mark - 提交评论
- (IBAction)Submitcomments:(id)sender {
    NSMutableDictionary  *dic=[NSMutableDictionary dictionary];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"museId"];
    [dic setObject:[Common getLoginInfo][@"userId"] forKey:@"memberId"];
    [dic setObject:[Common getLoginInfo][Key_User_password] forKey:@"musePwd"];
    [dic setObject:[Common getLoginInfo][Key_User_onlineKey] forKey:@"museOnlineTag"];
    
    self.shareApi.delegate=self;
    if ([_type isEqualToString:@"1"]) {//家教
        [dic setObject:_textView.text forKey:@"mlcoContent"];
        [dic setObject:@"1" forKey:@"mlcoType"];
       
        [dic setObject:_indentId forKey:@"orderId"];
        [dic setObject:_classId forKey:@"mallExpertId"];
        [self.shareApi  requestOperationWithDic:dic withPath:JY_mallLecturerComment withHttpType:@"POST" withTag:JY_JY_mallLecturerComment];

    }else{//课程
        [dic setObject:_textView.text forKey:@"mgcoContent"];
        [dic setObject:_indentId forKey:@"orderId"];
        [dic setObject:_classId forKey:@"mgooId"];
        [dic setObject:@"1" forKey:@"mgcoType"];
        [self.shareApi  requestOperationWithDic:dic withPath:JY_mallGoodsComment withHttpType:@"POST" withTag:JY_JY_mallGoodsComment];
    }
    
    

}

#pragma mark - <UITextViewDelegate>


- (void)textViewDidChange:(UITextView *)textView{
    
    if (self.textView.text.length > 0) {
        self.label.hidden = YES;
    }else{
        self.label.hidden = NO;
    }
    
}


#pragma   mark---- GetADBanner Request Delegate

-(void)fetchDatabaseFinished:(NSMutableDictionary *)database withTag:(NSInteger)tag{
    
    if (tag==JY_JY_mallLecturerComment || tag== JY_JY_mallGoodsComment) {
        if (  [[database valueForKey:@"flag"] integerValue]!=1 ) {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
        }else {
            [[CWHUDTips sharedInstance]  showTips:[database valueForKey:@"msg"]  withStatus:1 dismissAfter:1.5];
            [self backBtn];
        }
    }
}

-(void)fetchDatabaseFailed:(NSError *)error message:(NSString *)message{
        
        [self dismissWaitDialog];
    }
@end
